//
//  IconView.m
//  UI6_课后作业练习
//
//  Created by dllo on 15/11/16.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "IconView.h"

@implementation IconView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews
{
    self.backgroundColor = [UIColor whiteColor];

    UIScrollView *scrollV = [[UIScrollView alloc] initWithFrame:self.frame];
    scrollV.contentSize = CGSizeMake(0, self.frame.size.height * 3);
    scrollV.bounces = YES;
    scrollV.showsVerticalScrollIndicator = YES;
    [self addSubview:scrollV];
    [scrollV release];

    for (NSInteger i = 0; i < 10; i++) {
        
        NSString *fileName = [NSString stringWithFormat:@"image%ld.jpg", i + 1];
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(30, 60 + 175 * i, self.frame.size.width / 2 - 60, 125)];
        imageV.image = [UIImage imageNamed:fileName];
        imageV.userInteractionEnabled = YES;
        [scrollV addSubview:imageV];
        [imageV release];
        
        UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [imageV addGestureRecognizer:tapGR];
        [tapGR release];
        
    }
    
    for (NSInteger i = 0; i < 9; i++) {
        
        NSString *fileName = [NSString stringWithFormat:@"image%ld.jpg", i + 11];
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(30 + self.frame.size.width / 2, 60 + 175 * i, self.frame.size.width / 2 - 60, 125)];
        imageV.image = [UIImage imageNamed:fileName];
        imageV.userInteractionEnabled = YES;
        [scrollV addSubview:imageV];
        [imageV release];
        
        UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [imageV addGestureRecognizer:tapGR];
        [tapGR release];
        
    }


}


- (void)tapAction
{
    NSLog(@"轻拍");
}


@end
